import java.util.Arrays;

class Solution {
    public int firstMissingPositive(int[] nums) {
        int i=0,len=nums.length;
        int cnt;
        for(i=0;i<len;i++){
            if(nums[i]>0&&nums[i]<=len){
                cnt=nums[nums[i]-1];
                nums[nums[i]-1]=nums[i];
                nums[i]=cnt;
            }
        }
        System.out.println(Arrays.toString(nums));
        for(i=0;i<len;i++){
            if(nums[i]!=i+1)return i+1;
        }

        return len+1;
    }
}